package com.doubao.notepad_blog_backend.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.doubao.notepad_blog_backend.domain.BmsComment;
import com.doubao.notepad_blog_backend.domain.UmsUser;
import com.doubao.notepad_blog_backend.dto.CommentDTO;
import com.doubao.notepad_blog_backend.mapper.BmsCommentMapper;
import com.doubao.notepad_blog_backend.service.BmsCommentService;
import com.doubao.notepad_blog_backend.vo.CommentVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class BmsCommentServiceImpl extends ServiceImpl<BmsCommentMapper, BmsComment> implements BmsCommentService {
    @Resource
    private BmsCommentMapper commentMapper;

    @Override
    public List<CommentVO> getCommentsByPostID(String postid) {
        List<CommentVO> commentVOList = commentMapper.getCommentsByPostID(postid);
        return commentVOList;
    }

    @Override
    public BmsComment addComment(CommentDTO dto, UmsUser umsUser) {
        BmsComment comment = BmsComment.builder().userId(umsUser.getId())
                .content(dto.getContent())
                .postId(dto.getPost_id())
                .createTime(new Date())
                .build();
        this.save(comment);
        return comment;
    }
}
